package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.LinkMan;
import cn.wolfcode.crm.query.LinkManObject;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.ILinkManService;
import cn.wolfcode.crm.util.JSONResult;
import cn.wolfcode.crm.util.PageResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("linkMan")
public class LinkManController {

    @Autowired
    ILinkManService linkManService;

    @RequestMapping("")
    @RequiresPermissions(value = {"联系人首页","linkMan:index"} ,logical = Logical.OR)
    public String index(){

        return "linkMan/list";
    }

    @RequestMapping("list")
    @RequiresPermissions(value = {"联系人列表","linkMan:list"} ,logical = Logical.OR)
    @ResponseBody
    public PageResult list(LinkManObject qo){
        PageResult result = linkManService.query(qo);
        return result;
    }
    @RequestMapping("listData")
    @ResponseBody
    public Object listData(QueryObject qo){

        return linkManService.list();
    }

    @RequestMapping("save")
    @RequiresPermissions(value = {"联系人保存","linkMan:save"} ,logical = Logical.OR)
    @ResponseBody
    public JSONResult save(LinkMan entity){
        JSONResult result = new JSONResult();
        try{
            linkManService.save(entity);
        }catch(Exception e){
            e.printStackTrace();
            result.remark("操作失败");
        }
        return result;
    }

    @RequestMapping("update")
    @RequiresPermissions(value = {"联系人更新","linkMan:update"} ,logical = Logical.OR)
    @ResponseBody
    public JSONResult update(LinkMan entity){
        JSONResult result = new JSONResult();
        try{
            linkManService.update(entity);
        }catch(Exception e){
            e.printStackTrace();
            result.remark("操作失败");
        }
        return result;
    }


    @RequestMapping("delete")
    @RequiresPermissions(value = {"联系人删除","linkMan:delete"} ,logical = Logical.OR)
    @ResponseBody
    public JSONResult delete(Long id){
        JSONResult result = new JSONResult();
        try{
            linkManService.delete(id);
        }catch(Exception e){
            e.printStackTrace();
            result.remark("操作失败");
        }
        return result;
    }
}
